//
//  WJStatus.m
//  weibo
//
//  Created by 王俊 on 16/1/6.
//  Copyright © 2016年 王俊. All rights reserved.
//

#import "WJStatus.h"
#import "NSDate+WJNSDateExt.h"

@implementation WJStatus

+ (NSDictionary*)mj_objectClassInArray
{
    return @{@"pic_urls":[WJPhoto class]};
    
}
/*
 重写时间内容
 原时间显示格式：
 <a href="http://app.weibo.com/t/feed/1tqBja" rel="nofollow">360安全浏览器</a>
 */

- (void)setSource:(NSString *)source
{
    //_source = source;
    NSRange beginRange = [source rangeOfString:@">"];
    NSRange endRange = [source rangeOfString:@"</"];
    if ((beginRange.location != NSNotFound) && (endRange.location != NSNotFound)) {
        _source = [source substringWithRange:NSMakeRange(beginRange.location + 1, endRange.location - beginRange.location - 1)];
    }else{
        _source = @"";
    }
    
}

/*
 时间格式：Sat Jan 09 19:35:44 +0800 2016
 */


- (NSString*)created_at
{
    NSDateFormatter *format = [[NSDateFormatter alloc]init];
    //format.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"en_US"];
    format.dateFormat = @"EEE MMM dd HH:mm:ss Z yyyy";
    
    NSDate *date = [format dateFromString:_created_at];
    
    if ([date isThisYear]) {
        //今年
        if([date isToday]){
            //今天
            NSDateComponents *comps = [date deltaWithNow];
            if (comps.hour >= 1) {
                return [NSString stringWithFormat:@"%tu小时以前",comps.hour];
            }else if(comps.minute > 1){
                return [NSString stringWithFormat:@"%tu分钟以前",comps.minute];
            }else{
                
                return @"刚刚";
            }
            
        }else if([date isYesterday]){
            //昨天
            format.dateFormat = @"昨天 HH时:mm分";
            return [format stringFromDate:date];
        }else{
          //其它天
            format.dateFormat = @"MM月dd日 HH时:mm分";
            return [format stringFromDate:date];
        }
    }else{
        //非今年
        format.dateFormat = @"yyyy年 MM月dd日 HH时:mm分";
        return [format stringFromDate:date];
        
    }

}



@end
